<template>
  <div>
    <button
      v-for="item in tabs"
      :key="item"
      @click="itemClick(item)"
      :class="{ active: currentTab === item }"
    >
      {{ item }}
    </button>

    <!-- 动态组件 -->
    <keep-alive include="home,about">
      <compontent :is="currentTab" name="why" :age="18"></compontent>
    </keep-alive>

    <!-- v-if的判断实现 -->
    <!-- <template v-if="currentTab === 'Home'"><home></home></template>
    <template v-else-if="currentTab === 'About'"><about></about></template>
    <template v-else-if="currentTab === 'Category'"><category></category></template> -->
  </div>
</template>

<script>
import Home from "./pages/Home.vue";
import About from "./pages/About.vue";
import Category from "./pages/Category.vue";

export default {
  components: { About, Home, Category },
  data() {
    return {
      tabs: ["Home", "About", "Category"],
      currentTab: "Home",
    };
  },
  methods: {
    itemClick(item) {
      this.currentTab = item;
    },
  },
};
</script>

<style scoped>
.active {
  color: red;
}
</style>
